import { Button, Modal, message, Spin } from 'antd';

const confirm = Modal.confirm;
import { WeaErrorPage, WeaTools, WeaRadioGroup, WeaLocaleProvider } from 'ecCom';
import { WeaTableNew, WeaSwitch } from 'comsMobx';

const WeaTable = WeaTableNew.WeaTable;
import { inject, observer } from 'mobx-react';
import { toJS } from 'mobx';

const getLabel = WeaLocaleProvider.getLabel;
import CrmLogDetailDialog from '../dialog/CrmLogDetailDialog';

@observer
class ModifyRecord extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
    };
  }

  componentWillMount() {
    const { contentStore, contacterLog, sellchanceLog, location: { query } } = this.props;
    if (contacterLog == 'contacterLog') {
      contentStore.getViewLogCondition({ contacterLog });
    } else if (sellchanceLog == 'sellchanceLog') {
      contentStore.getViewLogCondition({ sellchanceLog });
    } else {
      contentStore.getViewLogCondition();
    }
    contentStore.clearRightMenu();
    contentStore.getViewLogRightMenu({ selectType: 'loginfo', ...query });
  }

  render() {
    const { contentStore } = this.props;
    const { modifyAuth: { verified, hasRight }, modifyTableStore, viewlogCondition } = contentStore;
    // if (verified && !hasRight) {
    //     return (<WeaAlertPage >
    //         <div style={{ color: '#000' }}>
    //             {getLabel(2012, "对不起，您暂时没有权限！")}
    //         </div>
    //     </WeaAlertPage>
    //     )
    // }
    // if (verified && hasRight) {
    return (
      <div style={{ height: '100%' }}>
        <WeaRadioGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaRadioGroup@pl0fxr`} config={toJS(viewlogCondition)} onChange={(params) => { this.onChange(params); }} />
        <WeaTable
          ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@d1rnln`}
          comsWeaTableStore={modifyTableStore}
          hasOrder
          needScroll
          getColumns={this.getColumns}
        />
        <CrmLogDetailDialog ecId={`${this && this.props && this.props.ecId || ''}_CrmLogDetailDialog@zymnts`} logStore={contentStore} />
      </div>
    );
    // }
    // return <div></div>
  }

    onChange = (params) => {
      const { contentStore, location: { query } } = this.props;
      if (params.operatorType > 0 && !params.operatorTypeDetail) {
      } else if (params.datetype_selectType === '6' && ((params.datetype_fromDate == '') || (params.datetype_toDate == ''))) {
      } else {
        contentStore.getViewLogList({ ...query, ...params });
      }
    }

    getColumns = columns => columns.map((col) => {
      if (col.dataIndex == 'logcontent') {
        return {
          ...col,
          render: (text, record, index) => (
            <span>

              { (record.newValuesspan || record.newValuesspan) ? <a onClick={() => this.showDialog(true, record)}>
                {getLabel(367, '查看')}
              </a> : <div>{text}</div>
              }
            </span>
          ),
        };
      }
      return col;
    });

    showDialog=(bl, record) => {
      const { contentStore } = this.props;
      contentStore.setDetailVisible(bl);
      contentStore.setDetailTitle(record.operateTypespan + record.logSmallTypeTargetIdspan);
      contentStore.updateDetailkey(`${new Date().getTime()}`);
      // record.randomFieldId = 1;
      // record.newValues = `{"modifytime":"09:34:35","ldapuser":"test11111"}`;
      // record.oldValues = `{"modifytime":"09:33:55","ldapuser":"test"}`;
      // record.params = `{"passingCert":"0","isPush":"1","request_header_user_agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36 Edg/80.0.361.66","ldapType":"AD","param_ip":"127.0.0.1","ldapUserForView":"test11111","factoryClass":"com.sun.jndi.ldap.LdapCtxFactory","ldapName":"测试1","isAuth":"0","ldapPassword":"EB00349D184181958D26C8B3997FCE4C","protocol":"ldap","modifyTime":"","ldapUser":"www.dcm.com.cn\\test11111","baseDomain":"www.dcm.com.cn","ldapId":"ceshi1","class":"class com.api.integration.ldap.bean.LdapBaseBean","createDate":"","keystorePassword":"","modifyDate":"","ip":"192.168.29.160","isPull":"1","isAdAccount":"0","isencryptPWD":"0","isUsed":"0","keystorePath":"","ldapPasswordEncrypt":"EB00349D184181958D26C8B3997FCE4C","createTime":"","port":"389","isSSO":"0"}`;
      contentStore.setDetailRecord(record);
    }
}

export default WeaTools.tryCatch(React,
  props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@s0e6rl`} msg={props.error ? props.error : getLabel(129417, '服务器运行出错，请联系系统管理员！')} />,
  { error: '' },
)(ModifyRecord);
